<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport"
	content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<title>邮宝洗衣</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<link href="../../css/type.css" rel="stylesheet" type="text/css">
<style type="text/css">
/*<![CDATA[*/
* html .decoration {
	position: absolute;
	right: 16px;
	top: 0;
} /*only for ie*/
/*]]>*/
</style>
<!-- Do not move the bellow script to custom.js! It must stay here to
    load properly! -->
<script type="text/javascript" src="../../scripts/jquery.js"></script>
<script type="text/javascript" src="../../scripts/custom.js" charset="utf-8"></script>
<script type="text/javascript" src="../../scripts/jquerysession.js"></script>
<script type="text/javascript" src="../../scripts/layer/layer.m.js"></script>
</head>
<body onLoad="loadImages()">
	<p class="no-mobile">
		请使用手机访问本页面！ <br /> 这个页面是专门针对手机设计的！
	</p>
	<div class="site">
		<div id="hidepage">
			<p class="center-text">
				加载中，请耐心等待! <br /> <img src="../../images/background/130.gif"
					alt="load">
			</p>
		</div>
		
		<div class="decoration">
			<div class="back">
				<a href="../../index.jsp?toPage=2">
					<img src="../../images/home/back.png">
				</a>
			</div> 
			<p class="title" style="width: 33%;float: left;">充值</p>
			<div style="width: 33%">
			</div> 
		</div>
		<div id="wrapper">
		<div class="person_recharge_table">
			<table border="0" cellspacing="0" cellpadding="0"  >
				<!-- <tr>
					<td class="pay_type_icon"><img  src="../../images/person/pay_type_01.png"></td>
					<td class="pay_tyep_text">支付宝支付</td>
					<td class="pay_select"><img  src="../../images/person/choice.png"></td>
				</tr> -->
				<tr>
					<td class="pay_type_icon"><img  src="../../images/person/pay_type_02.png"></td>
					<td class="pay_tyep_text">微信支付</td>
					<td class="pay_select"><img  src="../../images/person/choice.png"></td>
				</tr>
				<tr>
					<td colspan="3">余额:<font color="#ff6c0d">${param.balance}</font>元</td>
				</tr>
				<tr>
					<td colspan="3">金额:<input class="rechargemoney" style="width: 85%;height: 30px;" placeholder="请输入充值金额"></td>
				</tr>
			</table>
			<div class="next_lag" style="margin-top: 5%">
				<a href="javascript:void(0)" onclick="recharge()">
					<img src="../../images/person/recharge_lag.png">
				</a>
			</div> 
		</div>
	</div>
	</div>
		<script type="text/javascript">
		var outTradeNo;
		function recharge(){
			var money =$(".rechargemoney").val();
			if(money==""){
				//alert("请输入充值金额！");
				layer.open({content: '请输入充值金额！',time: 2});
				return false;
			}
			if(!validateMoney(money)){
				//alert("请输入输入正整数！");
				layer.open({content: '请输入输入正整数！',time: 2});
				return false;
			} 
			outTradeNo=getOrderNum();
			//alert(outTradeNo);
			var url="<%=path%>/transactionRouter";
			var params="funcID=0017&out_trade_no="+outTradeNo+"&body=YBXY&total_fee="+money+"&curPage=1&openid="+$.session.get('platformId');
			//var params="funcID=0017&out_trade_no="+outTradeNo+"&body=YBXY&total_fee="+money+"&curPage=1&openid=oNtWKjr4azG8R5A7J2gRI4OawFyQ";
			$.ajax({  
				type : "post",  
			    url : url,  
			    data : params,
			    dataType:'xml',
			    success : function(xml){ 
			    var return_code = $(xml).find("return_code").text();
			    //alert(return_code);
			    //alert(return_code=="SUCCESS");
				if(return_code=="SUCCESS"){
					var resultCode = $(xml).find("result_code").text();
					if(resultCode=="SUCCESS"){
						outTradeNo = $(xml).find("out_trade_no").text();
						curPage = $(xml).find("curPage").text();
						var prepay_id = $(xml).find("package").text();
						var appId = $(xml).find("appId").text();
						var timeStamp = $(xml).find("timeStamp").text();
						var pack = $(xml).find("package").text();
						var nonceStr = $(xml).find("nonce_str").text();
						var signType = $(xml).find("signType").text();
						var paySign =$(xml).find("paySign").text();
						//alert("appId="+appId.substr(9,36)+"&timeStamp="+timeStamp+"&nonceStr="+nonceStr+"&pack="+pack+"&signType="+signType+"&paySign="+paySign);
						if (typeof WeixinJSBridge == "undefined"){
							if( document.addEventListener ){
								document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
							}else if (document.attachEvent){
								document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
								document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
							}
						}else{
							onBridgeReady(appId,timeStamp,nonceStr,pack,signType,paySign);
						}
					}else{
						var errCodeDes=$(xml).find("err_code_des").text();
						alert(errCodeDes);
					}
				}else{
					var returnMsg=$(xml).find("return_msg").text();
					alert(returnMsg);
				}
			    },error: function(v){  
			        //alert("请求失败");
			        layer.open({content: '请输入输入正整数！',time: 2});
			    }
			  }); 
		}
		function onBridgeReady(appId,timeStamp,nonceStr,pack,signType,paySign){
			//alert("appId="+appId+"&timeStamp="+timeStamp+"&nonceStr="+nonceStr+"&pack="+pack+"&signType="+signType+"&paySign="+paySign);
		  	WeixinJSBridge.invoke(
		       'getBrandWCPayRequest', {
		           "appId" : appId,     //公众号名称，由商户传入     
		           "timeStamp": timeStamp,         //时间戳，自1970年以来的秒数     
		           "nonceStr" : nonceStr, //随机串     
		           "package" : pack,     
		           "signType" : signType,         //微信签名方式:     
		           "paySign" : paySign //微信签名 
		    },
		    function(res){  
		    	var url="<%=path%>/transactionRouter?funcID=0018&toPage=2&curPage="+curPage+"&out_trade_no="+outTradeNo;
		    	if(res.err_msg == "get_brand_wcpay_request:ok" ) {
		        	layer.open({content: '充值成功',time: 2,end: function(){location.href =url;}});
		        }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
		    }
		   ); 
		}
		//产生订单号
		function getOrderNum(){
			var orderNum="YBXYR"+new Date().Format("yyyyMMddhhmmssS");
			return orderNum;
		}
	</script>
</body>
</html>